package com.los.rabbitmq.workQueue;

import com.los.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: rabbitmq
 * @description: 工作队列发送消息
 * @author: Yujuan
 * @create: 2018-08-02 09:45
 **/
public class WorkSend {
    /**
     *                      ----c1
     * P------queue------
     *                      ----c2
     * @param args
     */
    private static  final String QUEUE_NAME="los_work_queue";
    public static void main(String[] args) throws InterruptedException {
        try {
            Connection connection= ConnectionUtils.getConnection();

            //获取通道
            Channel channel=connection.createChannel();
            //声明队列
            channel.queueDeclare(QUEUE_NAME,false,false,false,null);
            for (int i=0;i<50;i++
                 ) {
                String msg="Hello Los"+i;
                System.out.println("WQ send:"+msg);
                channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
                Thread.sleep(i*20);
            }
            channel.close();
            connection.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }

    }
}
